﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Text;
using System.Windows.Forms;

namespace Serviio.WHS
{
    public static class GuiHelper
    {
        public class BorderSides
        {
            public bool Left = true;
            public bool Top = true;
            public bool Right = true;
            public bool Bottom = true;
        }

        public static void GradientTitleBar(PaintEventArgs target, Panel panel, string titleText, Bitmap image)
        {
            Graphics g = target.Graphics;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Rectangle area = target.ClipRectangle;

            if (!target.ClipRectangle.Equals(panel.ClientRectangle))
            {
                area = panel.ClientRectangle;
            }

            LinearGradientBrush brush = new LinearGradientBrush(area, Color.White, Color.FromArgb(57, 105, 165), 0f);

            g.FillRectangle(brush, area);
            g.DrawImageUnscaled(image, 2, 2);
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            g.DrawString(titleText, new Font(new FontFamily("Tahoma"), 10f, FontStyle.Bold), new SolidBrush(Color.FromArgb(57, 69, 90)), 28f, 6f);
            PanelBorder(target, panel);
        }

        public static void PanelBorder(PaintEventArgs target, Panel panel, BorderSides sides = null)
        {
            Graphics g = target.Graphics;
            Rectangle area = target.ClipRectangle;
            if (!target.ClipRectangle.Equals(panel.ClientRectangle))
            {
                area = panel.ClientRectangle;
            }

            Pen pen = new Pen(Color.FromArgb(57, 105, 165));
            int x1 = 0;
            int y1 = 0;
            int x2 = area.Width - 1;
            int y2 = area.Height - 1;
            if (sides == null || sides.Top)
                g.DrawLine(pen, new Point(x1, y1), new Point(x2, y1));
            if (sides == null || sides.Left)
                g.DrawLine(pen, new Point(x1, y1), new Point(x1, y2));
            if (sides == null || sides.Right)
                g.DrawLine(pen, new Point(x2, y1), new Point(x2, y2));
            if (sides == null || sides.Bottom)
                g.DrawLine(pen, new Point(x1, y2), new Point(x2, y2));
        }

        public static void ToolStripBorder(PaintEventArgs target, ToolStrip toolStrip)
        {
            Graphics g = target.Graphics;
            Rectangle area = target.ClipRectangle;
            if (!target.ClipRectangle.Equals(toolStrip.ClientRectangle))
            {
                area = toolStrip.ClientRectangle;
            }

            Pen pen = new Pen(Color.FromArgb(57, 105, 165));
            Pen pen2 = new Pen(toolStrip.BackColor, 2);
            int x1 = 0;
            int y1 = 0;
            int x2 = area.Width;
            int y2 = area.Height - 2;
            g.DrawLine(pen2, new Point(x1, y1), new Point(x2, y1));
            g.DrawLine(pen2, new Point(x1, y1), new Point(x1, y2));
            g.DrawLine(pen2, new Point(x2, y1), new Point(x2, y2));
            g.DrawLine(pen, new Point(x1, y2), new Point(x2, y2));
        }

    }
}
